<?php

/**
 * 接口测试
 */
class TestController extends ControllerBase {

    public function indexAction() {

        header('Content-Type: ');

        echo '测试创建用户 ';

        // 测试创建用户
        $ret = Api::call('/user/modify/', [
            'uid' => 0,
            'name' => '',
            'phone' => rand(10000, 99999),
            'sex' => '',
            'passwd' => '123456'
        ], Api::API_REQUEST_METHOD_POST, false);

        var_dump($ret);

        echo PHP_EOL . '测试修改用户' . PHP_EOL;

        // 测试修改用户
        $ret = Api::call('/user/modify/', [
            'uid' => 77,
            'passwd' => '555'
        ], Api::API_REQUEST_METHOD_POST, false);

        var_dump($ret);

        echo PHP_EOL . '测试获取用户信息' . PHP_EOL;

        // 测试获取用户信息
        $ret = Api::call('/user/get_info/', [
            'uid' => 77
        ], Api::API_REQUEST_METHOD_POST, false);

        var_dump($ret);

        echo PHP_EOL . '测试用户鉴权 18565518404' . PHP_EOL;

        // 测试用户鉴权 18565518404
        $ret = Api::call('/user/identify/', [
            'phone' => 18565518404,
            'passwd' => '555'
        ], Api::API_REQUEST_METHOD_POST, false);

        var_dump($ret);

        echo PHP_EOL . '测试修改用户密码' . PHP_EOL;

        // 测试修改用户
        $ret = Api::call('/user/change_passwd/', [
            'phone' => 18565518404,
            'passwd' => '5555'
        ], Api::API_REQUEST_METHOD_POST, false);

        var_dump($ret);

        echo PHP_EOL . '测试用户鉴权修改密码之后 18565518404' . PHP_EOL;

        // 测试用户鉴权修改密码之后 18565518404
        $ret = Api::call('/user/identify/', [
            'phone' => 18565518404,
            'passwd' => '5555'
        ], Api::API_REQUEST_METHOD_POST, false);

        var_dump($ret);

        echo PHP_EOL . '测试验证码' . PHP_EOL;

        // 测试验证码
        $ret = Api::call('/user/get_valicode/', [], Api::API_REQUEST_METHOD_GET, false);

        var_dump($ret);

        echo PHP_EOL . '测试上传头像' . PHP_EOL;

        // 测试验证码
        $ret = Api::call('/user/upload_headimg/', [
            "uid" => 77,
            "data" => ""
        ], Api::API_REQUEST_METHOD_POST, false);

        var_dump($ret);

        echo PHP_EOL . '测试编辑收货地址' . PHP_EOL;

        // 测试编辑收货地址
        $ret = Api::call('/user/set_address/', [
            "aid" => 3,
            "uid" => 77,
            "uname" => "kooasdoasd asd asd ",
            "phone" => 18561254,
            "province" => 123123,
            "city" => 1231245,
            "dist" => 12456,
            "addrs" => 123,
        ], Api::API_REQUEST_METHOD_POST, false);

        var_dump($ret);

        echo PHP_EOL . '测试获取收货地址' . PHP_EOL;

        // 测试获取收货地址
        $ret = Api::call('/user/get_addresses/', ["uid" => 77], Api::API_REQUEST_METHOD_GET, false);

        var_dump($ret);

        echo PHP_EOL . '测试添加收藏' . PHP_EOL;

        // 测试添加收藏
        $ret = Api::call('/user/set_like/', [
            "uid" => 77,
            "product_id" => rand(1, 100)
        ], Api::API_REQUEST_METHOD_POST, false);
        var_dump($ret);
        $ret = Api::call('/user/set_like/', [
            "uid" => 77,
            "product_id" => rand(1, 100)
        ], Api::API_REQUEST_METHOD_POST, false);
        var_dump($ret);
        $ret = Api::call('/user/set_like/', [
            "uid" => 77,
            "product_id" => rand(1, 100)
        ], Api::API_REQUEST_METHOD_POST, false);
        var_dump($ret);

        echo PHP_EOL . '测试删除收藏' . PHP_EOL;

        // 测试删除收藏
        $ret = Api::call('/user/set_like/', [
            "uid" => 77,
            "product_id" => -1 * rand(1, 100)
        ], Api::API_REQUEST_METHOD_POST, false);
        var_dump($ret);

        echo PHP_EOL . '测试获取商品分类' . PHP_EOL;

        // 测试删除收藏
        $ret = Api::call('/category/get_list/', ["parent_id" => 0, 'ishome' => 1], Api::API_REQUEST_METHOD_GET, false);
        var_dump($ret);
    }

    public function tsAction() {

        header('Content-Type: ');

        echo PHP_EOL . '测试新增收货地址' . PHP_EOL;

        // 测试设置收货地址
        $ret = Api::call('/user/set_address/', [
            "aid" => 0,
            "uid" => 77,
            "uname" => "方法",
            "phone" => "687867464684",
            "province" => "阿斯顿按时打算的",
            "city" => "阿斯顿按时打算的",
            "dist" => "阿斯顿按时打算的",
            "addrs" => "阿斯顿按时打算的",
            "poscode" => "66494",
            "isdefault" => 1
        ], Api::API_REQUEST_METHOD_POST, false);

        var_dump($ret);

        echo PHP_EOL . '测试获取商品列表 ' . PHP_EOL;

        $ret = Api::call('/product/get_list/', [
            'catid' => 0,
            'searchkey' => '色'
        ], Api::API_REQUEST_METHOD_GET, false);

        #var_dump($ret);

        echo PHP_EOL . '测试获取商品信息 ' . PHP_EOL;

        $ret = Api::call('/product/get_info/', [
            'product_id' => 85
        ], Api::API_REQUEST_METHOD_GET, false);

        var_dump($ret);

        echo PHP_EOL . '测试创建订单 ' . PHP_EOL;

        $ret = Api::call('/order/create/', [
            'uid' => 77,
            'device_type' => 0,
            'paymethod' => 1,
            'exptime' => '2015-11-23 10:38:06',
            'aid' => 241,
            'order_data' => json_encode([
                ['product_id' => 144, 'product_count' => 1],
                ['product_id' => 29, 'product_count' => 2]
            ])
        ], Api::API_REQUEST_METHOD_POST, false);

        var_dump($ret);

        echo PHP_EOL . '测试添加收藏' . PHP_EOL;

        // 测试添加收藏
        $ret = Api::call('/user/set_like/', [
            "uid" => 77,
            "product_id" => "-1,-2"
        ], Api::API_REQUEST_METHOD_POST, false);
        var_dump($ret);

        echo PHP_EOL . '测试获取收藏' . PHP_EOL;

        // 测试获取收藏
        $ret = Api::call('/user/get_likes/', ["uid" => 77], Api::API_REQUEST_METHOD_GET, false);
        var_dump($ret);

        echo PHP_EOL . '测试反馈' . PHP_EOL;

        // 测试获取收藏
        $ret = Api::call('/feedback/add/', [
            "uid" => 77,
            'feedback' => 'asdasdasdasd'
        ], Api::API_REQUEST_METHOD_POST, false);
        var_dump($ret);

        echo PHP_EOL . '测试获取订单信息' . PHP_EOL;
        $ret = Api::call('/order/get_info/', ["order_id" => 173, 'device_type' => 1], Api::API_REQUEST_METHOD_GET, false);
        var_dump($ret);

        echo PHP_EOL . '测试获取订单列表' . PHP_EOL;
        $ret = Api::call('/order/get_list/', ["uid" => 165], Api::API_REQUEST_METHOD_GET, false);
        var_dump($ret);

        echo PHP_EOL . '测试评价商品' . PHP_EOL;
        $ret = Api::call('/order/comment/', [
            "uid" => 77,
            'product_id' => 144,
            'content' => 'asdasdasd'
        ], Api::API_REQUEST_METHOD_POST, false);
        var_dump($ret);

        echo PHP_EOL . '测试获取评论列表' . PHP_EOL;
        $ret = Api::call('/product/get_comments/', ["product_id" => 144], Api::API_REQUEST_METHOD_GET, false);
        var_dump($ret);
    }

    public function ts2Action() {

        header('Content-Type: ');

        echo PHP_EOL . '测试获取站内消息' . PHP_EOL;

        $ret = Api::call('/board/get_messages/', [
        ], Api::API_REQUEST_METHOD_GET, false);

        var_dump($ret);

        echo PHP_EOL . '测试获取未评价订单' . PHP_EOL;

        $ret = Api::call('/order/get_uncomment_list/', [
            'uid' => 77
        ], Api::API_REQUEST_METHOD_GET, false);

        #var_dump($ret);

        echo PHP_EOL . '测试删除收货地址' . PHP_EOL;

        $ret = Api::call('/user/del_address/', ["aid" => 240], Api::API_REQUEST_METHOD_POST, false);

        var_dump($ret);

        echo PHP_EOL . '测试获取可用积分' . PHP_EOL;

        $ret = Api::call('/order/get_credit_available/', [
            "uid" => 77,
            'amount' => 100
        ], Api::API_REQUEST_METHOD_POST, false);

        var_dump($ret);

        echo PHP_EOL . '测试获取顶部广告' . PHP_EOL;

        $ret = Api::call('/product/get_banners/', ["uid" => 77, 'amount' => 100], Api::API_REQUEST_METHOD_GET, false);

        var_dump($ret);

        echo PHP_EOL . '测试获取首推荐列表' . PHP_EOL;

        $ret = Api::call('/product/get_recomment_products/', [
            'pagesize' => 2
        ], Api::API_REQUEST_METHOD_GET, false);

        var_dump($ret);

        echo PHP_EOL . '测试确认收货' . PHP_EOL;

        $ret = Api::call('/order/confirm/', ["order_id" => 209], Api::API_REQUEST_METHOD_POST, false);

        var_dump($ret);

        echo PHP_EOL . '测试取消订单' . PHP_EOL;

        $ret = Api::call('/order/cancel/', ["order_id" => 208], Api::API_REQUEST_METHOD_POST, false);
        var_dump($ret);
    }

    public function tspayAction() {
        header('Content-Type: ');

        //        echo PHP_EOL . '测试支付回调' . PHP_EOL;
        //
        //        $ret = Api::call('/payment/alipay_notify/', [
        //            'out_trade_no' => '2015112610145556',
        //            'trade_no' => 'x',
        //            'trade_status' => 'TRADE_SUCCESS',
        //            'seller_email' => 'yj@yunjie-e.cn'
        //        ], Api::API_REQUEST_METHOD_POST, false);
        //
        //        var_dump($ret);

        echo PHP_EOL . '测试支付宝退款回调' . PHP_EOL;

        $ret = Api::call('/payment/alipay_refund_notify/', [
            'notify_type' => 'batch_refund_notify',
            'success_num' => 1,
            'batch_no' => hash('md4', time() . uniqid()),
            'result_details' => '2010031906272929^100^SUCCESS$jax_chuanhang@alipay.com^2088101003147483^0.01^SUCCESS',
            'out_trade_no' => '2015112610145556',
            'trade_no' => 'x',
            'trade_status' => 'TRADE_SUCCESS',
            'seller_email' => 'yj@yunjie-e.cn'
        ], Api::API_REQUEST_METHOD_POST, false);

        var_dump($ret);
    }

}
